package com.welleys.test.servlet.http.basic;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * by using webservlet annotation, so don't need config in web.xml, but still needs extends HttpServlet
 */
@WebServlet(name = "HiWebServlet", urlPatterns = "/hiwebservlet")
public class HiWebServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");

        PrintWriter printWriter = resp.getWriter();
        printWriter.println("<html><head><title>hiwebservlet-test</title></head><body>hi web servlet</body></html>");
        printWriter.flush();
        printWriter.close();
    }
}
